package com.ssy.lingxi.common.constant.basic;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户登录来源枚举
 * @author 万宁
 * @version 2.0.0
 * @date 2020-07-23
 */
public enum UserLoginSourceEnum {

    /**
     * 从业务平台Web客户端登录 - 1
     */
    BUSINESS_WEB(1, "业务中台Web"),

    /**
     * 从业务平台App客户端登录
     */
    BUSINESS_MOBILE(2, "业务中台App"),

    /**
     * 从平台后台登录 - 99
     */
    BUSINESS_MANAGEMENT_PLATFORM(99, "平台后台");

    /**
     * 枚举值
     */
    private Integer code;

    /**
     * 登录来源描述
     */
    private String message;

    UserLoginSourceEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public static boolean contains(Integer code) {
        return Arrays.stream(UserLoginSourceEnum.values()).anyMatch(s -> s.getCode().equals(code));
    }

    public static List<String> toStringList() {
        return Arrays.stream(UserLoginSourceEnum.values()).map(value -> String.valueOf(value.getCode())).collect(Collectors.toList());
    }

    public static UserLoginSourceEnum parseInt(Integer code) {
        return Arrays.stream(UserLoginSourceEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
    }
}
